<template>
  <el-dialog :title="isAdd +'Warranty Policy'"  :close-on-click-modal="false" :visible.sync="show" 
  class="dialog_index dialog_image" :before-close="cancle">
    <el-form ref="bannerForm" class="ourStoryForm">
      <el-tabs type="card" v-model="activeName">
          <el-tab-pane :label="item.site" :name="item.site"  v-for="item  in list" :key="item.id">
            <tinymce_editor v-model="item.article_detail"  :disabled="disabled"   ref="editor" ></tinymce_editor>

          </el-tab-pane>
      </el-tabs>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button type="search" :loading="isSubmit" @click="submitForm">保存</el-button>
      <el-button @click="cancle">取消</el-button>
    </span>
  </el-dialog>
</template>

<script>
import TinyMce from '@/components/Tinymce' 
import { editPost } from '@/api/aboutus/warrantyPolicy.js' 

export default {
  props: {
    show: Boolean,
    closeAddDialog:Function,
    isAdd: String
  },
  data() {
    return {
      list: [],
      isSubmit: false,
      activeName: 'US'
    }
  },
  watch: {
    show:function(){
      if(this.show){
        this.isSubmit = false
        this.activeName = this.$parent.curSite
        this.list =JSON.parse(JSON.stringify(this.$parent.list)) 
      }
    }
  },
  components:{tinymce_editor: TinyMce},
  methods:{
    submitForm(){
      if(!this.isSubmit) {
        this.add()
      }
    },
    add(){
      this.isSubmit = true
      let params = {
        data: JSON.stringify(this.list)
      }
      editPost(params).then(res=>{
        if(res.state == 1) {
          this.$message.success(this.isAdd + 'Warranty Policy成功')
          this.cancle()
        }
      })
    },
    cancle(){
      this.$emit('closeDialog')
      this.isSubmit = false
    },
  }
}
</script>

<style lang="scss">

</style>